#pragma once

#include <cocos2d.h>

class TextFieldTTFActionTest;

using namespace cocos2d;
using namespace std;

class ChessmanSprite;

class LoginLayer : public CCLayer
{
public:
	
	LoginLayer();
	virtual ~LoginLayer();
	
	virtual bool init();
	static cocos2d::CCScene* scene();
	//virtual void menuCloseCallback(CCObject* pSender);
	LAYER_NODE_FUNC(LoginLayer);
	//virtual void draw();
protected:
	void exitCallBack(CCObject* pSender);
	void loginCallBack(CCObject* pSender);
	TextFieldTTFActionTest * m_pNotificationLayer;
    void addKeyboardNotificationLayer(TextFieldTTFActionTest * pLayer);
    void addTextInputLayer();
    virtual void onEnter();
};

//////////////////////////////////////////////////////////////////////////
// KeyboardNotificationLayer for test IME keyboard notification.
//////////////////////////////////////////////////////////////////////////

class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate
{
public:
    KeyboardNotificationLayer();

    virtual std::string subtitle() = 0;
    virtual void onClickTrackNode(bool bClicked) = 0;

    virtual void registerWithTouchDispatcher();
    virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);

    // CCLayer
    virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

protected:
    CCNode * m_pTrackNode;
    CCPoint  m_beginPos;
};

//////////////////////////////////////////////////////////////////////////
// TextFieldTTFActionTest
//////////////////////////////////////////////////////////////////////////

class TextFieldTTFActionTest : public KeyboardNotificationLayer, public CCTextFieldDelegate
{
    CCTextFieldTTF *    m_pTextField;
    CCAction *          m_pTextFieldAction;
    bool                m_bAction;
    int                 m_nCharLimit;       // the textfield max char limit

public:
    void callbackRemoveNodeWhenDidAction(CCNode * pNode);
	const char *getText() {return m_pTextField->getString();}
    // KeyboardNotificationLayer
    virtual std::string subtitle();
    virtual void onClickTrackNode(bool bClicked);

    // CCLayer
    virtual void onEnter();
    virtual void onExit();

    // CCTextFieldDelegate
    virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);
    virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);
    virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);
    virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen);
    virtual bool onDraw(CCTextFieldTTF * pSender);
};